<template>
  <router-view />
</template>


<script setup lang="ts">
import { useStore } from 'vuex';
import { useRouter } from 'vue-router';
import { listDataAll, listDataAlltype } from './api';
import { showToast } from 'vant';

let store = useStore()
let router = useRouter()

let userData = localStorage.getItem("userData")
if (userData == null) {
  router.push({
    path: "/"
  })
} else {
  router.push({
    path: "/home"
  })
  store.commit('updateUserData', JSON.parse(userData))
}

listDataAll().then((result) => {

  store.commit('updateAllData', result.data.data)
}).catch((err) => {
  showToast('网络错误')
  console.log(err);
});

listDataAlltype().then((result) => {
  let data = result.data.data
  let results = {} as any;
  for (var i = 0; i < data.length; i++) {
    results[data[i]['goodsCategoryName']] = data[i];
  }
  store.commit('updatealllisttype', results)
}).catch((err) => {
  showToast('网络错误')
});
</script>

<style lang="less">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  background-color: #ffffff;
  min-height: 100vh;
}

nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style>
